﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class appleader_projects_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MasApp.BLL.Check.CheckLogin();
        if (!Page.IsPostBack)
        {
            if (Request["projectid"] != null)
            {
                searchproject();
            }
            else
            {
                MasApp.BLL.ResponseHelper.alert("非法链接", "editlist.aspx");
            }
            starttime.Attributes.Add("readonly", "true");
            endtime.Attributes.Add("readonly", "true");
        }
    }
    public void searchproject()
    {
        int projectid = int.Parse(Request["projectid"].ToString());
        
        MasApp.Model.project pro = MasApp.BLL.Search.SearchOneProject(projectid);
        string realname = MasApp.BLL.Search.SearchUserRealName(Session["username"].ToString());
        DataTable dt_model = MasApp.BLL.Search.SearchModelIDandName(int.Parse(Session["organizationid"].ToString()));
        DataTable dt_method = MasApp.BLL.Search.SearchMethodIDandName(int.Parse(Session["organizationid"].ToString()));

        tb_creator.Text = realname;
        tb_description.Text = pro.Description;
        tb_projectid.Text = pro.Projectid.ToString();
        tb_createdtime.Text = pro.Createdtime.ToString();
        tb_projectname.Text = pro.Projectname.ToString();
        tb_state.Text = pro.State;
        starttime.Text=pro.Starttime.ToString();
        endtime.Text = pro.Endtime.ToString();

        ddl_method.DataTextField = "methodname";
        ddl_method.DataValueField = "methodid";
        ddl_method.DataSource = dt_method;
        ddl_method.DataBind();
        ListItem item = ddl_method.Items.FindByValue(pro.Methodid.ToString());
        if (item != null)
        { item.Selected = true; }
        ddl_model.DataTextField = "modelname";
        ddl_model.DataValueField = "modelid";
        ddl_model.DataSource = dt_model;
        ddl_model.DataBind();
        item = ddl_model.Items.FindByValue(pro.Modelid.ToString());
        if (item != null)
        { item.Selected = true; }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        MasApp.Model.project pro = new MasApp.Model.project();
        pro.Description = tb_description.Text;
        pro.Methodid = int.Parse(ddl_method.SelectedValue);
        pro.Modelid = int.Parse(ddl_model.SelectedValue);
        pro.Projectname = tb_projectname.Text;
        pro.Starttime = Convert.ToDateTime(starttime.Text);
        pro.Endtime = Convert.ToDateTime(endtime.Text);
        pro.Projectid = int.Parse(tb_projectid.Text);
        if (MasApp.BLL.Update.UpdateProject(pro))
        {
            MasApp.BLL.ResponseHelper.alert("修改完成！", "edit.aspx?projectid=" + pro.Projectid.ToString());
        }
        else
        {
            MasApp.BLL.ResponseHelper.alert("修改不成功~", "editlist.aspx");
        }
    }
}
